﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace JAAF.Builders.Configuration
{

    /// <summary>
    /// Contains information on an implementation of an interface or base class abstraction.
    /// </summary>
    [ConfigurationCollection(typeof(ImplementationRegistration), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
    public class ImplementationRegistrations : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new ImplementationRegistration();
        }

        /// <summary>
        /// Provides the collection key for an implementation registration object
        /// </summary>
        /// <param name="_oElement">The collection element to provide the key for</param>
        /// <returns>A string containing the element's key.</returns>
        protected override object GetElementKey(ConfigurationElement _oElement)
        {
            return ((ImplementationRegistration)_oElement).Abstraction;
        }

        /// <summary>
        /// Gets the <see cref="ImplementationRegistration">implementation registration details</see>
        /// for a given abstraction name.
        /// </summary>
        /// <param name="_sAbstraction">The name of the abstract class / interface</param>
        /// <returns>An <see cref="ImplementationRegistration"/> object</returns>
        public ImplementationRegistration this[string _sAbstraction]
        {
            get
            {
                return (ImplementationRegistration)base.BaseGet(_sAbstraction);
            }
        }

        /// <summary>
        /// Gets the <see cref="ImplementationRegistration">implementation registration details</see>
        /// for an abstact class or interface.
        /// </summary>
        /// <param name="_oAbstractType">The type of the abstract class / interface.</param>
        /// <returns>An <see cref="ImplementationRegistration"/> object.</returns>
        public ImplementationRegistration this[Type _oAbstractType]
        {
            get
            {
                return (ImplementationRegistration)base.BaseGet(_oAbstractType.FullName);
            }
        }
    }
}
